package com.eden.api.controller;

import com.eden.api.controller.vo.ApiResult;
import com.eden.api.security.JwtUser;
import com.eden.api.security.LoginUser;
import com.eden.task.domain.UserTask;
import com.eden.task.service.IUserTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.eden.api.controller.vo.ApiResult.error;
import static com.eden.api.controller.vo.ApiResult.success;

/**
 * @program: eden
 * @description: 我的任务管理api接口
 * @author: Mr.Jiao
 * @create: 2021-05-03 15:07
 */

@Slf4j
@Api("我的任务管理")
@RestController
@RequestMapping("/api/myPublic")
public class ApiMyPublicController {
    @Autowired
    private IUserTaskService taskService;

    //查找我发布的任务
    @ApiOperation("查找我发布的任务")
    @PostMapping("/selMyPublic")
    public ApiResult selMyPublic() {
        LoginUser loginUser = JwtUser.getInstance().getLoginUser();
        List<UserTask> taskList = taskService.selectMyTaskList(loginUser.getLoginName());
        return success(taskList);
    }

    //修改我发布的任务
    @ApiOperation("修改我发布的任务")
    @PostMapping("/updMyPublic")
    public ApiResult updMyPublic(@Validated @RequestBody UserTask task) {
        LoginUser loginUser = JwtUser.getInstance().getLoginUser();
        UserTask userTask = new UserTask();
        userTask.setCreateBy(loginUser.getLoginName());
        return success();
    }

    //删除我发布的任务
    @ApiOperation("删除我发布的任务")
    @GetMapping("/delMyPublic")
    public ApiResult delMyPublic(String taskId) {
        if (taskId != null && taskId != "") {
            taskService.deleteUserTaskById(taskId);
            return success("删除成功！");
        } else {
            return error("删除失败！任务ID为空");
        }
    }

}
